/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 *
 * @author dloaiza
 */
@Entity
@Table(name = "TAB_ASTEROIDE")
@NamedQueries({
    @NamedQuery(name = "Asteroide.findAll", query = "SELECT a FROM Asteroide a")})
public class Asteroide implements Serializable {

    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @TableGenerator(name = "asteroideGen",
            table = "TBL_SQ",
            pkColumnName = "GEN_KEY",
            valueColumnName = "GEN_VALUE",
            pkColumnValue = "FAC_CON",
            initialValue = 0,
            allocationSize = 1)
    @GeneratedValue(strategy=GenerationType.TABLE, generator="asteroideGen")
    @Id
    @Basic(optional = false)
    @Column(name = "NMID_ASTEROIDE", nullable = false, precision = 0, scale = -127)
    private BigDecimal nmidAsteroide;
    @Column(name = "DSNOMBRE", length = 210)
    private String dsnombre;
    @Column(name = "NMRADIO", precision = 15)
    private Double nmradio;
    @Column(name = "DISTANCIA_SOL_REAL", precision = 126)
    private Double distanciaSolReal;
    @Column(name = "ORBITA_REAL", precision = 126)
    private Double orbitaReal;
    @JoinColumn(name = "UNIDAD_MEDIDA", referencedColumnName = "CDUNIDAD")
    @ManyToOne(fetch = FetchType.LAZY)
    private Unidaddistancia unidadMedida;
    @JoinColumn(name = "NMID_CLASIFICACION", referencedColumnName = "NMID_CLASIFICACION")
    @ManyToOne(fetch = FetchType.LAZY)
    private ClasificacionAsteroide nmidClasificacion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "asteroide", fetch = FetchType.LAZY)
    private List<Descubridor> descubridorList;

    public Asteroide() {
    }

    public Asteroide(BigDecimal nmidAsteroide) {
        this.nmidAsteroide = nmidAsteroide;
    }

    public BigDecimal getNmidAsteroide() {
        return nmidAsteroide;
    }

    public void setNmidAsteroide(BigDecimal nmidAsteroide) {
        this.nmidAsteroide = nmidAsteroide;
    }

    public String getDsnombre() {
        return dsnombre;
    }

    public void setDsnombre(String dsnombre) {
        this.dsnombre = dsnombre;
    }

    public Double getNmradio() {
        return nmradio;
    }

    public void setNmradio(Double nmradio) {
        this.nmradio = nmradio;
    }

    public Double getDistanciaSolReal() {
        return distanciaSolReal;
    }

    public void setDistanciaSolReal(Double distanciaSolReal) {
        this.distanciaSolReal = distanciaSolReal;
    }

    public Double getOrbitaReal() {
        return orbitaReal;
    }

    public void setOrbitaReal(Double orbitaReal) {
        this.orbitaReal = orbitaReal;
    }

    public Unidaddistancia getUnidadMedida() {
        return unidadMedida;
    }

    public void setUnidadMedida(Unidaddistancia unidadMedida) {
        this.unidadMedida = unidadMedida;
    }

    public ClasificacionAsteroide getNmidClasificacion() {
        return nmidClasificacion;
    }

    public void setNmidClasificacion(ClasificacionAsteroide nmidClasificacion) {
        this.nmidClasificacion = nmidClasificacion;
    }

    public List<Descubridor> getDescubridorList() {
        return descubridorList;
    }

    public void setDescubridorList(List<Descubridor> descubridorList) {
        this.descubridorList = descubridorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (nmidAsteroide != null ? nmidAsteroide.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Asteroide)) {
            return false;
        }
        Asteroide other = (Asteroide) object;
        if ((this.nmidAsteroide == null && other.nmidAsteroide != null) || (this.nmidAsteroide != null && !this.nmidAsteroide.equals(other.nmidAsteroide))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.alexstarkbd.jpa.entities.Asteroide[ nmidAsteroide=" + nmidAsteroide + " ]";
    }

    @PostLoad
    public void fixIt() {
        this.descubridorList = new ArrayList<Descubridor>(this.descubridorList);
    }
}
